package com.app.megaprosoft.modyimcarcare;

import com.megaprosoft.modyimcarcare.R;

import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TextView;

public class ListServices extends Activity {

	Button btn1, btn2, Sum;
	TextView TextSum, et1, et2, et3, et4, et5, et6, et7, et8, et9;
	EditText disc, prom;
	CheckBox c1, c2, c3, c4, c5, c6, c7, c8, c9;
	RadioButton rbA, rbB, rbC, rb5, rb6;
	String list1_1, list1_2, list1_3, list2, list3, list4_1, list4_2, list5,
			list6, list7, list8, list9;
	int a, d, e, f, g, h, i, j, k, sum;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
		setContentView(R.layout.activity_list_services);

		matching();

		btn1 = (Button) findViewById(R.id.button1);
		Sum = (Button) findViewById(R.id.ButtonSum);
		btn2 = (Button) findViewById(R.id.button2);
		TextSum = (TextView) findViewById(R.id.Sum);
		disc = (EditText) findViewById(R.id.discount);
		prom = (EditText) findViewById(R.id.promotion);

		a = choice1();
		e = choice2();
		choice3();
		choice4();
		choice5();
		choice6();
		choice7();
		choice8();
		choice9();

		Sum.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				System.out.println(a + "      " + e);
				sum = a + e;
				TextSum.setText("" + sum);

			}

		});

		/*
		 * TextSum.setText(Integer.parseInt(et1.getText().toString())
		 * +Integer.parseInt(et2.getText().toString()) +
		 * Integer.parseInt(et3.getText().toString())
		 * +Integer.parseInt(et4.getText().toString())
		 * +Integer.parseInt(et6.getText().toString())
		 * +Integer.parseInt(et6.getText().toString())
		 * +Integer.parseInt(et7.getText
		 * ().toString())+Integer.parseInt(et8.getText().toString()) +
		 * Integer.parseInt(et9.getText().toString()));
		 */

		// TextSum.setText(Integer.parseInt(et9.getText().toString()));

		// TextSum.setText(a);

		btn1.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {

				// Open Form Add
				Intent newActivityAdd = new Intent(ListServices.this,
						Card.class);
				startActivity(newActivityAdd);

			}

		});

		btn2.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {

				// Open Form Add
				Intent newActivityAdd = new Intent(ListServices.this,
						InitialServices.class);
				startActivity(newActivityAdd);

			}

		});

	}

	public int choice1() {

		int aa = 0;
		c1.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {

				if (c1.isChecked()) {
					rbA.setOnClickListener(new View.OnClickListener() {

						@Override
						public void onClick(View v) {

							if (c1.isChecked() && rbA.isChecked()) {
								et1.setText("1000");
								list1_1 = "Premium ��ҧ�Ѵ�մ/�������ͧ  ��ҧ�������";
								a = Integer.parseInt(et1.getText().toString());

							} else {
								et1.setText("");

							}
						}

					});

					rbB.setOnClickListener(new View.OnClickListener() {

						@Override
						public void onClick(View v) {

							if (c1.isChecked() && rbB.isChecked()) {
								et1.setText("89");
								// int
								list1_2 = "Premium ��ҧ�Ѵ�մ/�������ͧ ��ҧ��������";
								a = Integer.parseInt(et1.getText().toString());

							} else
								et1.setText("");
							a = Integer.parseInt(et1.getText().toString());

						}

					});

					rbC.setOnClickListener(new View.OnClickListener() {

						@Override
						public void onClick(View v) {

							if (c1.isChecked() && rbC.isChecked()) {
								et1.setText("100");
								list1_3 = "Premium ��ҧ�Ѵ�մ/�������ͧ  �����ҧ";
								a = 500;

							} else
								et1.setText("");
							a = 0;

						}

					});

				}

				else {

					rbA.clearComposingText();
					rbB.clearComposingText();
					rbC.clearFocus();
					et1.setText("");

				}

			}

		});
		System.out.println(aa);
		return aa;

	}

	public int choice2() {

		c2.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {

				if (c2.isChecked()) {

					et2.setText("500");
					list2 = c2.getText().toString();
					d = Integer.parseInt(et2.getText().toString());

				} else {
					et2.setText("");
				}
				d = 0;
			}
		});
		return d;

	}

	public void choice3() {

		c3.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {

				if (c3.isChecked()) {

					et3.setText("100");
					list3 = c3.getText().toString();
					e = 1500;
				} else {

					et3.setText("");
					e = 0;
				}

			}
		});

	}

	public void choice4() {

		c4.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {

				if (c4.isChecked()) {
					rb5.setOnClickListener(new View.OnClickListener() {

						@Override
						public void onClick(View v) {

							if (c4.isChecked() && rb5.isChecked()) {
								et4.setText("100");
								list4_1 = "��ҧ��ͧ����ͧ���  �������";
								f = 1500;
							} else {
								et4.setText("");
								f = 0;
							}
						}

					});

					rb6.setOnClickListener(new View.OnClickListener() {

						@Override
						public void onClick(View v) {

							if (c4.isChecked() && rb6.isChecked()) {
								et4.setText("100");
								list4_2 = "��ҧ��ͧ����ͧ���  ��������";
								f = 2500;
							} else
								et4.setText("");
							f = 0;
						}

					});

				}

				else {

					rb5.clearComposingText();
					rb6.clearComposingText();
					et4.setText("");
				}

			}

		});

	}

	public void choice5() {

		c5.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {

				if (c5.isChecked()) {

					et5.setText("110");
					list5 = c5.getText().toString();
					g = 100;
				} else {

					et5.setText("");
					g = 0;
				}

			}
		});

	}

	public void choice6() {

		c6.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {

				if (c6.isChecked()) {

					et6.setText("100");
					list6 = c6.getText().toString();
					h = 500;
				} else {

					et6.setText("");
					h = 0;
				}

			}
		});

	}

	public void choice7() {

		c7.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {

				if (c7.isChecked()) {

					et7.setText("100");
					list7 = c7.getText().toString();
					i = 400;
				} else {

					et7.setText("");
					i = 0;
				}

			}
		});

	}

	public void choice8() {

		c8.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {

				if (c8.isChecked()) {

					et8.setText("100");
					list8 = c8.getText().toString();
					j = 300;
				} else {

					et8.setText("");
					j = 0;
				}

			}
		});

	}

	public void choice9() {

		c9.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {

				if (c9.isChecked()) {

					et9.setText("100");
					list9 = c9.getText().toString();
					// k = 200;
					TextSum.setText(Integer.parseInt(et9.getText().toString()));
				} else {

					et9.setText("");
					k = 0;
					// TextSum.setText(Integer.parseInt(et9.getText().toString()));
				}

			}
		});

	}

	public void matching() {
		c1 = (CheckBox) this.findViewById(R.id.check1);
		rbA = (RadioButton) this.findViewById(R.id.rb1);
		rbB = (RadioButton) this.findViewById(R.id.rb2);
		rbC = (RadioButton) this.findViewById(R.id.rb3);
		et1 = (TextView) this.findViewById(R.id.result1);

		c2 = (CheckBox) this.findViewById(R.id.check2);
		et2 = (TextView) this.findViewById(R.id.result2);
		c4 = (CheckBox) this.findViewById(R.id.check4);
		rb5 = (RadioButton) this.findViewById(R.id.rb5);
		rb6 = (RadioButton) this.findViewById(R.id.rb6);
		et4 = (TextView) this.findViewById(R.id.result4);

		c3 = (CheckBox) this.findViewById(R.id.check3);
		et3 = (TextView) this.findViewById(R.id.result3);

		c5 = (CheckBox) this.findViewById(R.id.check5);
		et5 = (TextView) this.findViewById(R.id.result5);
		c6 = (CheckBox) this.findViewById(R.id.check6);
		et6 = (TextView) this.findViewById(R.id.result6);
		c7 = (CheckBox) this.findViewById(R.id.check7);
		et7 = (TextView) this.findViewById(R.id.result7);

		c8 = (CheckBox) this.findViewById(R.id.check8);
		et8 = (TextView) this.findViewById(R.id.result8);

		c9 = (CheckBox) this.findViewById(R.id.check9);
		et9 = (TextView) this.findViewById(R.id.result9);
		TextSum = (TextView) findViewById(R.id.Sum);

	}

	@Override
	public void onBackPressed() {

		new AlertDialog.Builder(this)
				.setTitle("¡��ԡ��÷���¡��")
				.setMessage("��Ѻ�˹����ѡ")
				.setNegativeButton(android.R.string.yes,
						new DialogInterface.OnClickListener() {

							public void onClick(DialogInterface arg0, int arg1) {
								Intent newActivity = new Intent(
										getApplicationContext(),
										MainActivity.class);
								startActivity(newActivity);
								finish();
								overridePendingTransition(R.layout.fadeendout,
										R.layout.fadeendin);
							}
						}).setPositiveButton(android.R.string.no, null)
				.create().show();

	}

	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.list_services, menu);
		return true;
	}

}
